// 短信模板
import {
  trim, compact, get, isEmpty
} from 'lodash';
import { DataTypes, Model, UUIDV4 } from 'sequelize';
import { MySqlModel, getSequelize } from '../db';

class SmsTemplate extends MySqlModel {

}

SmsTemplate.init({
  id: {
    type: DataTypes.UUID, unique: 'id', allowNull: false, defaultValue: UUIDV4, validate: { isUUID: 4 }, primaryKey: true, comment: '主键'
  },
  hotel_id: {
    type: DataTypes.UUID, allowNull: false, validate: { isUUID: 4 }, comment: '主体'
  },
  template_code: {
    type: DataTypes.STRING(50), allowNull: false, comment: '短信模板CODE'
  },
  template_content: { // 短信模板内容
    type: DataTypes.STRING(500), allowNull: false, comment: '短信模板内容'
  },
  template_rule: { //name,nickname,code
    type: DataTypes.STRING(200), allowNull: false, comment: '短信模板变量名称'
  },
  created_at: {
    type: DataTypes.DATE, allowNull: false, comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE, allowNull: false, comment: '更新时间'
  },
  version: {
    type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '版本控制'
  }
}, {
  sequelize: getSequelize(),
  tableName: 'sms_template',
  comment: '短信模板',
  indexes: [
    { fields: ['hotel_id', 'template_code'], unique: true }
  ]
});

// https://sequelize.org/api/v6/class/src/model.js~model#static-method-hasMany

export default SmsTemplate;
